<?php

$o = $params[0];
$type = isset($params[1]) ? $params[1] : NULL;

$link = '#';

switch ($type) {
case 'imagestorage':
	$thumb_name = isset($params[2]) ? $params[2] : 'orig';
	$oid = $o;
	if (is_array($oid)) $oid = $oid['oid'];
	$oid = intval($oid);
	if ($oid) {
		$image = $tpl->get('rh')->ctx->store->getObject($oid);
		$mime_type = $image->data['mime_type'];
		switch ($mime_type) {
		case 'image/png': $ext = 'png'; break;
		case 'image/jpg':
		case 'image/jpeg': $ext = 'jpg'; break;
		case 'image/gif': $ext = 'gif'; break;
		case 'image/bmp': $ext = 'bmp'; break;
		default: $ext = 'img';
		}
		$link = "imagestorage/$oid/$thumb_name.$ext";
	}
	break;
default:
	$link = $tpl->apm($o, 'url', 'geturl');
}

echo $link;

?>
